package zhupf.test.threadTest.reentreLockDemo;

import lombok.Data;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@Data
public class LockDemo {
    private Lock lock = new ReentrantLock();

    private int flag;


    public void lockMethod(){
        lock.lock();
        try {

            System.out.println(">>>>>>>>>>>>>>>> come in "+Thread.currentThread().getName());
            TimeUnit.MILLISECONDS.sleep(flag);
            System.out.println(">>>>>>>>>>>>>>>> sleep  over "+Thread.currentThread().getName());

        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

}
